package com.jaws.core.common.exception;
import com.jaws.core.common.vo.OpResponse;
import com.jaws.core.mvc.exception.IErrors;

/**
 * API 前置的异常码划分为:
 * @author maojian
 *
 * <li>公共模块: 100,公共模块错误码: 110000~110999</li>
 * @date 2017-05-10 17:53:03
 * @since v1.0.0
 */
public enum JawsCommonExceptionCode implements IErrors<OpResponse>{
    TOKEN_CHECK_ERROR(1100001 , "TOKEN校验错误"),
    PARAM_ERROR(1100002 , "参数校验不合法%s"),
    SIGN_AUTHENTICATION_ERROR(1000003 , "接口签名不正确"),
    SNOWFLAKE_CONFIG_ERROR(1100004,"snowflake workerId超过1024"),
    SNOWFLAKE_WORKERID_ERROR(1100005,"snowflake workerId超过1024"),
    SNOWFLAKE_CENTERID_ERROR(1100006,"snowflake centerId超过8"),
    SNOWFLAKE_SWITH_OFF(1100007,"雪花算法未配置"),
    SNOWFLAKE_INETADDRESS_ERROR(1100008,"Cannot get LocalHost InetAddress, please check your network!"),
    TAG_NOT_FOUND(1100009, "[{0}]中找不到tag:[{1}]"),
    TEMPLATE_FILE_NOT_FOUND(1100010, "找不到模板[{0}]"),
    EXCEL_FILE_NOT_FOUND(1100011, "找不到被导入的excel[{0}]"),
    ILLEGAL_PARAM(1100012, "Excel参数异常:{0}"),
    APOLLO_LOCAL_FILE_LOAD_ERROR(1100013,"阿波罗本地文件加载失败!"),
    EXCEL_MODELMAP_ERROR(1100014, "ModelMap template transfer error!"),
    SYSTEM_ERROR(110999, "系统错误");



    private int code;
    private String desc;
    private JawsCommonExceptionCode(int code,String desc){
        this.code = code;
        this.desc = desc;
    }
    public int getCode() {
        return code;
    }
    public void setCode(int code) {
        this.code = code;
    }
    public String getDesc() {
        return desc;
    }
    public void setDesc(String desc) {
        this.desc = desc;
    }

    @Override
    public OpResponse parse() {
        OpResponse result = new OpResponse();
        result.setCode(code);
        result.setDisplay(desc);
        return result;
    }

    @Override
    public OpResponse parse(Object... args) {
        OpResponse result = new OpResponse();
        result.setCode(code);
        String formatReason = String.format(desc, args);
        result.setDisplay(formatReason);
        return result;
    }

    @Override
    public OpResponse parseMsg(String message, Object... args) {
        this.desc = message;
        return parse(args);
    }

    @Override
    public JawsCommonException exp() {
        return new JawsCommonException(code, desc);
    }

    @Override
    public JawsCommonException exp(Object... args) {
        String formatReason = String.format(desc, args);
        return new JawsCommonException(code, formatReason);
    }

    @Override
    public JawsCommonException expMsg(String message, Object... args) {
        String formatReason = String.format(message, args);
        return new JawsCommonException(code, formatReason);
    }
    @Override
    public JawsCommonException exp(Throwable arg0, Object... arg1) {
        return null;
    }
    @Override
    public JawsCommonException expMsg(String arg0, Throwable arg1, Object... arg2) {
        return null;
    }


}
